#!/usr/bin/python3
# -*- coding: utf-8 -*-

from rich.console import Console
from rich.table import Table


def rich_table(
    test_report=None,
    test_phase=None,
    test_id=None,
    run_results=None,
    case_name=None,
    case_path=None,
    case_annotation=None,
    case_model=None,
    test_time=None,
    exception_info=None,
):
    """
    格式化打印测试阶段报告
    :return:
    """
    data = {
        "测试报告": str(test_report),
        "测试阶段": str(test_phase),
        "用例ID": str(test_id),
        "运行结果": str(run_results),
        "用例名称": str(case_name),
        "用例路径": str(case_path),
        "用例注释": str(case_annotation),
        "用例模块": str(case_model),
        "执行耗时": str(test_time),
        "异常信息": str(exception_info),
    }
    table = Table(title="测试阶段报告")
    table.add_column("描述", justify="center", style="cyan", no_wrap=True)
    table.add_column("详细信息", style="magenta")

    for key, value in data.items():
        table.add_row(key, value, style="green")

    console = Console()
    console.rule("\n [bold red] 阶段性测试报告", align="center")
    console.print(table, style="cyan", justify="center")


if __name__ == "__main__":
    rich_table(
        test_report="test_case_01",
        test_phase="setup",
        test_id="001",
        run_results="passed",
        case_name="test_case_01",
        case_path="/rr/erer/erer",
        case_annotation="hello world",
        case_model="acads",
        test_time="3s",
        exception_info="",
    )
